//
//  ByViewIndexSection.m
//  jinpuyiyuan_ios
//
//  Created by mc on 2017/12/5.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByViewIndexSection.h"

// vc
#import "ByIndexHealthVC.h"
#import "ByUserIndexLookDoctorVC.h"

@implementation ByViewIndexSection
{
    NSString     *_titleStr;
    NSString     *_imgStr;
    
}
- (instancetype)initWithFrame:(CGRect)frame andTitle:(NSString *)title andImg:(NSString *)img{
    if (self == [super initWithFrame:frame]) {
        _titleStr = title;
        _imgStr = img;
        self.backgroundColor = [UIColor whiteColor];
        [self createViews];
    }
    return self;
}

- (void)createViews{
    // img(1:1 = 30:30)
    UIImageView *img = [[UIImageView alloc] init];
    [self addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(10));
        make.top.equalTo(@(0));
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    img.image = [UIImage imageNamed:_imgStr];
    
    // 更多
    UIImageView *moreImg = [[UIImageView alloc] init];
    [self addSubview:moreImg];
    [moreImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-10));
        make.top.equalTo(@(10));
        make.size.mas_equalTo(CGSizeMake(20, 20));
    }];
    moreImg.image = [UIImage imageNamed:@"Index_jiantou"];
    
    UIButton *moreButton = [[UIButton alloc] init];
    [self addSubview:moreButton];
    CGFloat width = [@"更多" getSizeOfString:14].width + 10;
    [moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(moreImg.mas_left).offset(-10);
        make.top.equalTo(@(10));
        make.size.mas_equalTo(CGSizeMake(width, 20));
    }];
    [moreButton setTitle:@"更多" forState:UIControlStateNormal];
    [moreButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    moreButton.titleLabel.font = FONT(14);
    [moreButton addTarget:self action:@selector(moreAction) forControlEvents:UIControlEventTouchUpInside];
    
    // 标题
    UILabel *titleLabel = [[UILabel alloc] init];
    [self addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(img.mas_right).offset(10);
        make.top.equalTo(@(5));
        make.right.equalTo(moreButton.mas_left).offset(-10);
        make.bottom.equalTo(@(-5));
    }];
    titleLabel.font = FONT(18);
    titleLabel.text = _titleStr;
    
}

- (void)moreAction{
    if ([_titleStr isEqualToString:@"健康资讯"]) {
        ByIndexHealthVC *vc = [[ByIndexHealthVC alloc] init];
        [(ByBaseVC *)self.viewController by_normalPush:vc hasNavi:YES];
    }else{
        ByUserIndexLookDoctorVC *vc = [[ByUserIndexLookDoctorVC alloc] init];
        [(ByBaseVC *)self.viewController by_normalPush:vc hasNavi:YES];
    }
    
}

@end
